<template>
  <div ref="container">
    <breadcrumb :breadList="breadList" :name="name">
      <!-- <div class="handle-box" slot="handleContent">
        <div class="handle-btn">
          <a-button class="common-btn" @click="go_toOperation('create', '')">添加项目</a-button>
        </div>
        <div class="handle-btn">
          <a-button class="common-btn">导出列表</a-button>
        </div>
      </div> -->
    </breadcrumb>
    <a-card>
      <a-form @submit="handleSubmit" :form="form">
        <a-row clss="form-row" :gutter="16">
          <a-col :lg="8" :md="12" :sm="24">
            <a-form-item label="姓名" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 14}, sm: {span: 17} }">
              <a-input v-model="queryParam.proName" placeholder="姓名" style="width:220px;"/>
            </a-form-item>
          </a-col>
          <a-col :lg="8" :md="12" :sm="24">
            <a-form-item label="身份证号" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 14}, sm: {span: 17} }">
              <a-input v-model="queryParam.proCode" rows="1" placeholder="身份证号" style="width:220px;"/>
            </a-form-item>
          </a-col>
          <a-col :lg="8" :md="12" :sm="24">
            <a-form-item label="所属项目" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 14}, sm: {span: 17} }">
              <a-input v-model="queryParam.proItem" rows="1" placeholder="所属项目" style="width:220px;"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row clss="form-row" :gutter="16">
          <a-col :lg="8" :md="12" :sm="24">
            <a-form-item label="所在地区" :labelCol="{lg: {span: 6}, sm: {span: 7}}" :wrapperCol="{lg: {span: 14}, sm: {span: 17} }">
              <a-select v-decorator="['queryParam.eara', {initialValue: '1', rules: [{required: false, message: ''}]}]" style="width: 220px;">
                <a-select-option value="1">山西省</a-select-option>
                <a-select-option value="2">陕西省</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :lg="2" :md="12" :sm="24">
            <a-form-item label="" :colon="false">
              <a-button class="common-btn" @click="toSearch('2')">查询</a-button>
            </a-form-item>
          </a-col>
          <a-col :lg="4" :md="12" :sm="24">
            <a-form-item label="" :colon="false">
              <a-button class="common-btn" @click="$refs.warningSearchModel.add('')">高级搜索</a-button>
            </a-form-item>
          </a-col>
        </a-row>
        <warning-search-model ref="warningSearchModel" @closeModel="closeModel"></warning-search-model>
      </a-form>
    </a-card>
    <a-card>
      <a-table
        :columns="columns"
        :dataSource="loadData"
        bordered
        :loading="loading"
        :pagination="false"
        :scroll="{ x: 1200 }">
        <template slot="operation" slot-scope="text, record">
          <p style="display:inline" @click="go_toOperation('detail',record)" v-if="record.confirmed === '是'">
            <a href="javascript:;">详情</a>
            <a-divider type="vertical"/>
          </p>
          <p style="display:inline" @click="toRepair(record)" v-if="record.confirmed === '是'">
            <a href="javascript:;">维修</a>
          </p>
          <p style="display:inline" @click="go_toOperation('create',record)" v-if="record.confirmed === '否'">
            <a href="javascript:;">报警确认</a>
          </p>
        </template>
      </a-table>
    </a-card>
  </div>
</template>

<script>
import Breadcrumb from '@/components/tools/Breadcrumb'
import WarningSearchModel from './warningSearchModel'
// import { getSupplierList } from '@/api/mockdata'
export default {
  name: 'AlarmUserQuery',
  components: {
    Breadcrumb,
    WarningSearchModel
  },
  data () {
    return {
      name: '',
      breadList: [],
      loading: false,
      form: this.$form.createForm(this),
      // 查询参数
      queryParam: {},
      // 表头
      columns: [
        {
          title: '报警级别',
          width: '8%',
          dataIndex: 'alarmLevel'
        }, {
          title: '优先级',
          width: '8%',
          dataIndex: 'priority'
        }, {
          title: '发生时间',
          width: '8%',
          dataIndex: 'occurrenceTime'
        }, {
          title: '报警点',
          width: '12%',
          dataIndex: 'alarmPoints'
        }, {
          title: '用户',
          width: '8%',
          dataIndex: 'user'
        }, {
          title: '联系电话',
          width: '8%',
          dataIndex: 'telephone'
        },
        {
          title: '报警内容',
          width: '8%',
          dataIndex: 'alarmContent'
        },
        {
          title: '是否确认',
          width: '8%',
          dataIndex: 'confirmed'
        },
        {
          title: '确认人',
          width: '8%',
          dataIndex: 'confirmingPerson'
        },
        {
          title: '确认时间',
          width: '12%',
          dataIndex: 'confirmingTime'
        },
        {
          title: '操作',
          dataIndex: 'operation',
          scopedSlots: { customRender: 'operation' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: []
    }
  },
  created () {
    this.loading = true
    this.getBreadCrumb()
    setTimeout(() => {
      this.getData('1')
    }, 1000)
  },
  methods: {
    // 面包屑处理
    getBreadCrumb () {
      this.breadList = []
      this.name = this.$route.name
      this.$route.matched.forEach(item => {
        console.log('1111', item)
        this.breadList.push(item)
      })
    },
    getData (code) {
      const data = [
        {
          alarmLevel: 'A',
          priority: '3',
          occurrenceTime: '2020/1/26',
          alarmPoints: '小店区北格镇小格村',
          user: '小格村委会',
          telephone: '13877828727',
          alarmContent: '停机',
          confirmed: '是',
          confirmingPerson: '管理员',
          confirmingTime: '2020/1/26 10:27',
          identityType: '2'
        }, {
          alarmLevel: 'B',
          priority: '2',
          occurrenceTime: '2020/1/26',
          alarmPoints: '小店区北格镇小格村',
          user: '汪峰',
          telephone: '13909987366',
          alarmContent: '低温',
          confirmed: '否',
          confirmingPerson: '-',
          confirmingTime: '-',
          identityType: '1'
        }, {
          alarmLevel: 'A',
          priority: '3',
          occurrenceTime: '2020/1/26',
          alarmPoints: '小店区北格镇小格村',
          user: '小格村委会',
          telephone: '13877828727',
          alarmContent: '停机',
          confirmed: '是',
          confirmingPerson: '管理员',
          confirmingTime: '2020/1/26 10:27',
          identityType: '2'
        }, {
          alarmLevel: 'B',
          priority: '2',
          occurrenceTime: '2020/1/26',
          alarmPoints: '小店区北格镇小格村',
          user: '汪峰',
          telephone: '13909987366',
          alarmContent: '低温',
          confirmed: '否',
          confirmingPerson: '-',
          confirmingTime: '-',
          identityType: '1'
        }, {
          alarmLevel: 'A',
          priority: '3',
          occurrenceTime: '2020/1/26',
          alarmPoints: '小店区北格镇小格村',
          user: '小格村委会',
          telephone: '13877828727',
          alarmContent: '停机',
          confirmed: '是',
          confirmingPerson: '管理员',
          confirmingTime: '2020/1/26 10:27',
          identityType: '2'
        }, {
          alarmLevel: 'B',
          priority: '2',
          occurrenceTime: '2020/1/26',
          alarmPoints: '小店区北格镇小格村',
          user: '汪峰',
          telephone: '13909987366',
          alarmContent: '低温',
          confirmed: '否',
          confirmingPerson: '-',
          confirmingTime: '-',
          identityType: '1'
        }
      ]
      if (code === '1') {
        this.loadData = data
        setTimeout(() => {
          this.loading = false
        }, 1000)
      } else {
        this.loadData = data
        setTimeout(() => {
          this.loading = false
          this.$success({
            title: '查询成功'
          })
        }, 1000)
      }
    },
    toSearch (status) {
      this.loading = true
      this.getData(status)
    },
    handleSubmit () {
      console.log('ttt')
    },
    toRepair () {
      this.$success({
        title: '当前报警已安排维修'
      })
    },
    closeModel () {
      this.getData('2')
    },
    go_toOperation (type, record) {
      console.log('========', record)
      this.$router.push({
        name: 'alarmDetails',
        query: {
          type: type,
          proDetails: JSON.stringify(record)
        }
      })
    }
  }
}

</script>

<style lang="less" scoped>
// .handle-box {
//  Display: flex;
//   margin-bottom: 10px;
//   margin-left: 800px;
// }
// .handle-btn {
//   margin-left:5px;
// }
</style>
